//
//  TTMusicLeftPageViewController.m
//  TTMusic
//
//  Created by chenpengyu on 16/3/30.
//  Copyright © 2016年 cpy. All rights reserved.
//

#import "TTMusicLeftPageViewController.h"
#import "NightViewController.h"
#import "AppDelegate.h"
@interface TTMusicLeftPageViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIImageView *imageViewBeiJing;

@end

@implementation TTMusicLeftPageViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    

    
    [self CreatTableView];
    
    // Do any additional setup after loading the view.
}
-(void)CreatTableView {
        
   self.imageViewBeiJing = [[UIImageView alloc] initWithFrame:self.view.bounds];
    self.imageViewBeiJing.image = [UIImage imageNamed:@"chouti.jpeg"];
    [self.view addSubview:self.imageViewBeiJing];
    
    UITableView *tableview = [[UITableView alloc] init];
    self.tableView = tableview;
    tableview.frame = self.view.bounds;
    tableview.dataSource = self;
    tableview.delegate  = self;
    tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:tableview];
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *Identifier = @"Identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Identifier];
    }
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    cell.textLabel.font = [UIFont systemFontOfSize:20.0f];
    cell.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = [UIColor whiteColor];
    
    if (indexPath.row == 0) {
        cell.textLabel.text = @"登录";
    } else if (indexPath.row == 1) {
        cell.textLabel.text = @"夜间模式";
    } else if (indexPath.row == 2) {
        cell.textLabel.text = @"清除缓存";
    }     return cell;
}

//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
//
//        otherViewController *vc = [[otherViewController alloc] init];
//
//        [tempAppDelegate.mainNavigationController pushViewController:vc animated:NO];
//    
//    
//    otherViewController *otherVC = [[otherViewController alloc]init];
//    
//    [self.navigationController pushViewController:otherVC animated:YES];
//}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 250;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.bounds.size.width, 180)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    AppDelegate *tempAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//    [tempAppDelegate.LeftSlideVC closeLeftView];//关闭左侧抽屉

    
    if (indexPath.row == 0) {
        
        

        
        
    }else if (indexPath.row == 1){
        
        NightViewController *nightVC = [[NightViewController alloc]init];
        
//        [self.navigationController pushViewController:nightVC animated:YES];
//        
        [self presentViewController:nightVC animated:YES completion:^{
            
        }];
        
        
    }else if (indexPath.row == 2) {
        
        SDImageCache *sd = [SDImageCache sharedImageCache];
        float size = [sd getSize] / 1024.0/1024.0;
        
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"清除缓存" message:[NSString stringWithFormat:@"当前缓存为%.2fMB", size]preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [sd clearDisk];
        }];
        
        [alert addAction:cancel];
        [alert addAction:sure];
        
        [self presentViewController:alert animated:YES completion:^{
            
        }];

        
        
    }
    
    
    
    
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
